package com.dubbo.test.redisNew;

import com.dubbo.test.lock.JedisConnectionUtils;
import redis.clients.jedis.Jedis;

/**
 * @ Author xsd
 * @ crate time 2020/7/24 9:05
 * @ 描述 redis 发布 订阅
 * zj: 发  jedis.publish(channel,msg)
 *     订阅  subscribe(JedisPubSub --》extends JedisPubSub _onMessage, String... channels)
 */
public class redisFbDy {
    static Jedis jedis = JedisConnectionUtils.getJedis();

    private static Long publish(){
        System.out.println("开始发布_");
        Long res = null;
        try {
            // 客户端配置监听两个channel
            new Thread(()->{
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //发布
                jedis.publish("channel", "hello world 8888");
            }).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    public static void main1(String[] args) {
        publish();
    }
}
